/**
 *  JSimProd - Java simulation code for production processes
 *  Copyleft Jorge Mira Yagüe <jorge.mira.yague@gmail.com>
 *  Universidad de Alicante 2009
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package lib.model.distribution;

import java.util.Random;
import lib.xml.XMLizable;

/**
 * The class distribution defines a probability distribution, but doesn't define
 * the type of the distribution, and how the results are returned.
 * @author Jorge Mira Yagüe
 */
public abstract class Distribution implements XMLizable {

    protected DistributionType type;
    protected double mean;
    protected double variance;
    protected Random random;

    /**
     * Builds a distribution with the given parameters
     * @param type the type of the distribution
     * @param mean the mean value of the distribution
     * @param variance the variance of the distribution
     * @see DistributionType
     */
    public Distribution(DistributionType type, double mean, double variance) {
        this.type = type;
        this.mean = mean;
        this.variance = variance;
        random = new Random();
    }

    public DistributionType getType() {
        return type;
    }

    public double getMean() {
        return mean;
    }

    public double getVariance() {
        return variance;
    }

    /**
     * Returns a random value depending on the parameters given
     * @return the random value of the distribution
     */
    public abstract double getResult();

    public String toXML() {
        String result = "<Distribution ";
        result += "type=\"" + type + "\" ";
        result += "mean=\"" + mean + "\" ";
        result += "variance=\"" + variance + "\" ";
        result += "/>\n";
        return result;
    }
}
